package com.buddy.syn.block._07;

public class SynBlockStringService {

    private String userNameParam;
    private String passwordParam;
//    private String anyString = new String();

    public void setUserNamePassword(String userName,String password){
        try {
            String anyString = new String();
            synchronized (anyString){
                System.out.println("线程名称："+Thread.currentThread().getName()
                        +" 在 "+System.currentTimeMillis()+" 进入同步块！");
                userNameParam = userName;
                Thread.sleep(3000);
                passwordParam = password;
                System.out.println("线程名称："+Thread.currentThread().getName()
                        +" 在 "+System.currentTimeMillis()+" 离开同步块！参数：userNameParam= "+userName+",passwordParam="+passwordParam);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
